
const userInfo = {
  username: '',
  password: '',
  token: '',
  STUDENT_ID: '',
};

// 使用正确的导出语法
export const useUserStore = defineStore({
  id: 'user',
  state: () => ({
    userInfo
  }),
  getters: {
    getUsername: (state) => state.userInfo.username,
    getToken: (state) => state.userInfo.token,
    getSTUDENT_ID: (state) => state.userInfo.STUDENT_ID,
    getPassword: (state) => state.userInfo.password,
    getSecurityQuestion: (state) => state.userInfo.securityQuestion,
  },
  actions: {
    setUserInfo(result) {
      this.userInfo.username = result.username;
      this.userInfo.token = result.token;
      this.userInfo.STUDENT_ID = result.STUDENT_ID;
      this.userInfo.password = result.password;
      this.userInfo.securityQuestion = result.securityQuestion;
    },
    // 添加清除用户信息的方法
    clearUserInfo() {
      this.userInfo.username = '';
      this.userInfo.password = '';
      this.userInfo.token = '';
      sessionStorage.removeItem('token');
    }
  }
});
